home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg2.cab / style_collector.xsl < prev    next >
Extensible Markup Language  |  2005-09-10  |  28KB  |  676 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.     OpenOffice.org - a multi-platform office productivity suite
  5.  
  6.     $RCSfile: style_collector.xsl,v $
  7.  
  8.     $Revision: 1.5 $
  9.  
  10.     last change: $Author: rt $ $Date: 2005/09/08 22:01:43 $
  11.  
  12.     The Contents of this file are made available subject to
  13.     the terms of GNU Lesser General Public License Version 2.1.
  14.  
  15.  
  16.       GNU Lesser General Public License Version 2.1
  17.       =============================================
  18.       Copyright 2005 by Sun Microsystems, Inc.
  19.       901 San Antonio Road, Palo Alto, CA 94303, USA
  20.  
  21.       This library is free software; you can redistribute it and/or
  22.       modify it under the terms of the GNU Lesser General Public
  23.       License version 2.1, as published by the Free Software Foundation.
  24.  
  25.       This library is distributed in the hope that it will be useful,
  26.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.       Lesser General Public License for more details.
  29.  
  30.       You should have received a copy of the GNU Lesser General Public
  31.       License along with this library; if not, write to the Free Software
  32.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33.       MA  02111-1307  USA
  34.  
  35. -->
  36. <!--
  37.     For further documentation and updates visit http://xml.openoffice.org/sx2ml
  38. -->
  39. <xsl:stylesheet version="1.0"
  40.         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  41.         xmlns:office="http://openoffice.org/2000/office"
  42.         xmlns:style="http://openoffice.org/2000/style"
  43.         xmlns:text="http://openoffice.org/2000/text"
  44.         xmlns:table="http://openoffice.org/2000/table"
  45.         xmlns:draw="http://openoffice.org/2000/drawing"
  46.         xmlns:fo="http://www.w3.org/1999/XSL/Format"
  47.         xmlns:xlink="http://www.w3.org/1999/xlink"
  48.         xmlns:number="http://openoffice.org/2000/datastyle"
  49.         xmlns:svg="http://www.w3.org/2000/svg"
  50.         xmlns:chart="http://openoffice.org/2000/chart"
  51.         xmlns:dr3d="http://openoffice.org/2000/dr3d"
  52.         xmlns:math="http://www.w3.org/1998/Math/MathML"
  53.         xmlns:form="http://openoffice.org/2000/form"
  54.         xmlns:script="http://openoffice.org/2000/script"
  55.         xmlns:dc="http://purl.org/dc/elements/1.1/"
  56.         xmlns:meta="http://openoffice.org/2000/meta"
  57.         xmlns:config="http://openoffice.org/2001/config"
  58.         xmlns:help="http://openoffice.org/2000/help"
  59.         xmlns:xt="http://www.jclark.com/xt"
  60.         xmlns:common="http://exslt.org/common"
  61.         xmlns:xalan="http://xml.apache.org/xalan"
  62.         exclude-result-prefixes="office style text table draw fo xlink number svg chart dr3d math form script dc meta config help xt common xalan">
  63.  
  64.  
  65.  
  66.     <!-- ***************************************** -->
  67.     <!-- *** Gathering office style properties *** -->
  68.     <!-- ***************************************** -->
  69.  
  70.     <!-- REASON FOR STYLESHEET:
  71.             In the OpenOffice documents styles are represented by a hierarchy.
  72.             (e.g. most styles are inherited from a default style).
  73.             Many other languages (as XHTML/CSS) do not support inherited styles.
  74.             The style inheritance have to be made flat/absolute for each style.
  75.  
  76.             A further reason was, that the earlier style collection mechanism
  77.             had problems with CSS inline, which do not inherit from XML office defaults
  78.             nor font:family defaults as the style header does
  79.             (cp. stylesheet 'style_collector.xsl' and the 'write-default-styles' template)
  80.  
  81.          RESULT OF STYLESHEET:
  82.             All styles will be returned in a variable containing styles with their inherited style:properties:
  83.  
  84.                 <all-styles>
  85.                     <style style:family="foo" style:name="x1">
  86.                         <style:properties fo:margin-left="0cm" fo:margin-right="0cm" />
  87.                     </style>
  88.                     <style style:family="muh" style:name="x2" >
  89.                         <style:properties fo:margin-left="3cm" ...                  />
  90.                     </style>
  91.                     ...
  92.  
  93.                 </all-styles>
  94.     -->
  95.  
  96.  
  97.     <xsl:template name="collect-global-OOo-properties">
  98.         <!-- to access the variable as a node-set by XPATH expressions, it is necessary to convert it
  99.              from a result-tree-fragment (RTF) to a node set by a in a XSLT 1.0 non standarized function -->
  100.         <xsl:variable name="globalDataRTF">
  101.             <xsl:call-template name="collect-document-links-RTF" />
  102.         </xsl:variable>
  103.  
  104.         <xsl:choose>
  105.             <xsl:when test="function-available('xalan:nodeset')">
  106.                 <xsl:call-template name="collect-style-properties">
  107.                     <xsl:with-param name="globalData" select="xalan:nodeset($globalDataRTF)" />
  108.                 </xsl:call-template>
  109.             </xsl:when>
  110.             <xsl:when test="function-available('xt:node-set')">
  111.                 <xsl:call-template name="collect-style-properties">
  112.                     <xsl:with-param name="globalData" select="xt:node-set($globalDataRTF)" />
  113.                 </xsl:call-template>
  114.             </xsl:when>
  115.             <xsl:when test="function-available('common:node-set')">
  116.                 <xsl:call-template name="collect-style-properties">
  117.                     <xsl:with-param name="globalData" select="common:node-set($globalDataRTF)" />
  118.                 </xsl:call-template>
  119.             </xsl:when>
  120.             <xsl:otherwise>
  121.                 <xsl:message terminate="yes">The required node-set function was not found!</xsl:message>
  122.             </xsl:otherwise>
  123.         </xsl:choose>
  124.     </xsl:template>
  125.  
  126.  
  127.  
  128.     <xsl:template name="collect-style-properties">
  129.         <xsl:param name="globalData" />
  130.  
  131.         <!-- Add the input file references to the new collected style properties -->
  132.         <xsl:variable name="globalDataRTF">
  133.             <xsl:copy-of select="$globalData" />
  134.             <xsl:call-template name="collect-style-properties-RTF">
  135.                 <xsl:with-param name="globalData" select="$globalData" />
  136.             </xsl:call-template>
  137.         </xsl:variable>
  138.  
  139.         <xsl:choose>
  140.             <xsl:when test="function-available('xalan:nodeset')">
  141.                 <xsl:call-template name="map-ooo-style-properties">
  142.                     <xsl:with-param name="globalData" select="xalan:nodeset($globalDataRTF)" />
  143.                 </xsl:call-template>
  144.             </xsl:when>
  145.             <xsl:when test="function-available('xt:node-set')">
  146.                 <xsl:call-template name="map-ooo-style-properties">
  147.                     <xsl:with-param name="globalData" select="xt:node-set($globalDataRTF)" />
  148.                 </xsl:call-template>
  149.             </xsl:when>
  150.             <xsl:when test="function-available('common:node-set')">
  151.                 <xsl:call-template name="map-ooo-style-properties">
  152.                     <xsl:with-param name="globalData" select="common:node-set($globalDataRTF)" />
  153.                 </xsl:call-template>
  154.             </xsl:when>
  155.             <xsl:otherwise>
  156.                 <xsl:message terminate="yes">The required node-set function was not found!</xsl:message>
  157.             </xsl:otherwise>
  158.         </xsl:choose>
  159.     </xsl:template>
  160.  
  161.  
  162.     <xsl:template name="collect-document-links-RTF">
  163.         <!-- works for zipped office files, unzipped office files as for flat filter single office file format as well -->
  164.         <xsl:variable name="documentLinksRTF">
  165.             <xsl:choose>
  166.                 <xsl:when test="office:document-content">
  167.                     <xsl:element name="styles-file" namespace="">
  168.                         <xsl:copy-of select="document(concat($sourceBaseURL, 'styles.xml'))" />
  169.                     </xsl:element>
  170.                     <xsl:element name="meta-file" namespace="">
  171.                         <xsl:copy-of select="document(concat($sourceBaseURL, 'meta.xml'))" />
  172.                     </xsl:element>
  173.                 </xsl:when>
  174.                 <xsl:otherwise>
  175.                     <xsl:element name="styles-file" namespace="">
  176.                         <xsl:copy-of select="/" />
  177.                     </xsl:element>
  178.                     <xsl:element name="meta-file" namespace="">
  179.                         <xsl:copy-of select="/" />
  180.                     </xsl:element>
  181.                 </xsl:otherwise>
  182.             </xsl:choose>
  183.         </xsl:variable>
  184.  
  185.         <xsl:choose>
  186.             <xsl:when test="function-available('xalan:nodeset')">
  187.                 <xsl:call-template name="collect-document-links">
  188.                     <xsl:with-param name="documentLinks" select="xalan:nodeset($documentLinksRTF)" />
  189.                 </xsl:call-template>
  190.             </xsl:when>
  191.             <xsl:when test="function-available('xt:node-set')">
  192.                 <xsl:call-template name="collect-document-links">
  193.                     <xsl:with-param name="documentLinks" select="xt:node-set($documentLinksRTF)" />
  194.                 </xsl:call-template>
  195.             </xsl:when>
  196.             <xsl:when test="function-available('common:node-set')">
  197.                 <xsl:call-template name="collect-document-links">
  198.                     <xsl:with-param name="documentLinks" select="common:node-set($documentLinksRTF)" />
  199.                 </xsl:call-template>
  200.             </xsl:when>
  201.             <xsl:otherwise>
  202.                 <xsl:message terminate="yes">The required node-set function was not found!</xsl:message>
  203.             </xsl:otherwise>
  204.         </xsl:choose>
  205.  
  206.     </xsl:template>
  207.  
  208.  
  209.     <xsl:template name="collect-document-links">
  210.         <xsl:param name="documentLinks" />
  211.  
  212.         <xsl:element name="styles-file" namespace="">
  213.             <xsl:copy-of select="$documentLinks/styles-file/*" />
  214.         </xsl:element>
  215.  
  216.         <xsl:element name="meta-file" namespace="">
  217.             <xsl:copy-of select="$documentLinks/meta-file/*" />
  218.         </xsl:element>
  219.  
  220.         <xsl:copy-of select="$documentLinks/styles-file/*/office:styles" />
  221.         <xsl:copy-of select="$documentLinks/styles-file/*/office:font-decls" />
  222.  
  223.         <!-- office:automatic-styles may be containted in two files (i.e. content.xml and styles.xml).
  224.              Wild card necessary as top level element differs from flat office files ("SampleName.fsxw") -->
  225.         <xsl:copy-of select="/*/office:automatic-styles" />
  226.  
  227.     </xsl:template>
  228.  
  229.  
  230.     <xsl:template name="collect-style-properties-RTF">
  231.         <xsl:param name="globalData" />
  232.  
  233.        <!--** DEFAULT STYLES: First adding some office defaults unwritten in XML -->
  234.         <xsl:variable name="defaultOfficeStyle-RTF">
  235.             <xsl:element name="style" namespace="">
  236.                 <xsl:element name="style:properties">
  237.                    <!-- otherwise it would be written as '* { margin:0; padding:0;}' into the CSS header' -->
  238.                     <xsl:if test="$outputType = 'CSS_INLINED'">
  239.                         <xsl:attribute name="fo:margin-left">0</xsl:attribute>
  240.                         <xsl:attribute name="fo:margin-right">0</xsl:attribute>
  241.                     </xsl:if>
  242.                 </xsl:element>
  243.             </xsl:element>
  244.         </xsl:variable>
  245.  
  246.         <xsl:choose>
  247.             <xsl:when test="function-available('xalan:nodeset')">
  248.                 <xsl:call-template name="collect-properties-defaults">
  249.                     <xsl:with-param name="globalData" select="$globalData" />
  250.                     <xsl:with-param name="defaultOfficeStyle" select="xalan:nodeset($defaultOfficeStyle-RTF)" />
  251.                 </xsl:call-template>
  252.             </xsl:when>
  253.             <xsl:when test="function-available('xt:node-set')">
  254.                 <xsl:call-template name="collect-properties-defaults">
  255.                     <xsl:with-param name="globalData" select="$globalData" />
  256.                     <xsl:with-param name="defaultOfficeStyle" select="xt:node-set($defaultOfficeStyle-RTF)" />
  257.                 </xsl:call-template>
  258.             </xsl:when>
  259.             <xsl:when test="function-available('common:node-set')">
  260.                 <xsl:call-template name="collect-properties-defaults">
  261.                     <xsl:with-param name="globalData" select="$globalData" />
  262.                     <xsl:with-param name="defaultOfficeStyle" select="common:node-set($defaultOfficeStyle-RTF)" />
  263.                 </xsl:call-template>
  264.             </xsl:when>
  265.             <xsl:otherwise>
  266.                 <xsl:message terminate="yes">ERROR: Function not found: 'Nodeset'</xsl:message>
  267.             </xsl:otherwise>
  268.         </xsl:choose>
  269.     </xsl:template>
  270.  
  271.  
  272.     <xsl:template name="collect-properties-defaults">
  273.         <xsl:param name="globalData" />
  274.         <xsl:param name="defaultOfficeStyle" />
  275.  
  276.         <!--** DEFAULT STYLES: Adding the default styles of a style:family, by adding each office:styles/style:default-style element **-->
  277.         <xsl:variable name="defaultFamilyStyles-RTF">
  278.             <xsl:for-each select="$globalData/office:styles/style:default-style">
  279.                 <xsl:element name="style" namespace="">
  280.                     <xsl:copy-of select="@style:family" />
  281.                     <xsl:call-template name="create-inherited-style-properties">
  282.                         <xsl:with-param name="inheritedStyleProperties" select="$defaultOfficeStyle/style/style:properties" />
  283.                     </xsl:call-template>
  284.                 </xsl:element>
  285.             </xsl:for-each>
  286.         </xsl:variable>
  287.  
  288.         <xsl:choose>
  289.             <xsl:when test="function-available('xalan:nodeset')">
  290.                 <xsl:call-template name="collect-properties">
  291.                     <xsl:with-param name="globalData" select="$globalData" />
  292.                     <xsl:with-param name="defaultOfficeStyle" select="$defaultOfficeStyle" />
  293.                     <xsl:with-param name="defaultFamilyStyles" select="xalan:nodeset($defaultFamilyStyles-RTF)" />
  294.                 </xsl:call-template>
  295.             </xsl:when>
  296.             <xsl:when test="function-available('xt:node-set')">
  297.                 <xsl:call-template name="collect-properties">
  298.                     <xsl:with-param name="globalData" select="$globalData" />
  299.                     <xsl:with-param name="defaultOfficeStyle" select="$defaultOfficeStyle" />
  300.                     <xsl:with-param name="defaultFamilyStyles" select="xt:node-set($defaultFamilyStyles-RTF)" />
  301.                 </xsl:call-template>
  302.             </xsl:when>
  303.             <xsl:when test="function-available('common:node-set')">
  304.                 <xsl:call-template name="collect-properties">
  305.                     <xsl:with-param name="globalData" select="$globalData" />
  306.                     <xsl:with-param name="defaultOfficeStyle" select="$defaultOfficeStyle" />
  307.                     <xsl:with-param name="defaultFamilyStyles" select="common:node-set($defaultFamilyStyles-RTF)" />
  308.                 </xsl:call-template>
  309.             </xsl:when>
  310.             <xsl:otherwise>
  311.                 <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  312.             </xsl:otherwise>
  313.         </xsl:choose>
  314.     </xsl:template>
  315.  
  316.  
  317.     <xsl:template name="collect-properties">
  318.         <xsl:param name="globalData" />
  319.         <xsl:param name="defaultOfficeStyle" />
  320.         <xsl:param name="defaultFamilyStyles" />
  321.  
  322.        <!--** traversee all style trees - branch after branch - collecting style properties **-->
  323.         <xsl:element name="all-ooo-styles" namespace="">
  324.  
  325.        <!-- Background Information:
  326.  
  327.            There are two different types of styles in the Office:
  328.                1) The office:styles from the user pre-defined style templates
  329.                2) The automatic:styles, which are created whenever a user uses explicit style formatting.
  330.  
  331.            The office:styles only have parent styles in the office:styles,
  332.            but automatic:styles may inherit from both office:styles and themself.
  333.         -->
  334.  
  335.            <!--** traversee all office:styles trees beginning with the top-level styles **-->
  336.             <xsl:for-each select="$globalData/office:styles/style:style[not(@style:parent-style-name)]">
  337.                <!-- Looking for parents from style:family
  338.                <xsl:for-each select="$globalData/office:styles/style:style[@style:family=current()/@style:family][not(@style:parent-style-name)]"> -->
  339.                 <xsl:choose>
  340.                     <xsl:when test="$defaultFamilyStyles/style[@style:family=current()/@style:family]">
  341.                         <xsl:call-template name="inherit-style-for-self-and-children">
  342.                             <xsl:with-param name="globalData" select="$globalData" />
  343.                             <xsl:with-param name="inheritedStyleProperties" select="$defaultFamilyStyles/style[@style:family=current()/@style:family]/style:properties" />
  344.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="false()" />
  345.                         </xsl:call-template>
  346.                     </xsl:when>
  347.                     <xsl:otherwise>
  348.                         <xsl:call-template name="inherit-style-for-self-and-children">
  349.                             <xsl:with-param name="globalData" select="$globalData" />
  350.                             <xsl:with-param name="inheritedStyleProperties" select="$defaultOfficeStyle/style/style:properties" />
  351.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="false()" />
  352.                         </xsl:call-template>
  353.                     </xsl:otherwise>
  354.                 </xsl:choose>
  355.                <!--** creates a style element with style:name and style:family attribute and
  356.                        an element representing the absolute style properties style:property  ** -->
  357.             </xsl:for-each>
  358.  
  359.        <!--** traversee all office:automatic-styles trees beginning with the top-level styles **-->
  360.             <xsl:for-each select="$globalData/office:automatic-styles/style:style[not(@style:parent-style-name)]">
  361.                <!--** creates a style element with style:name and style:family attribute and
  362.                        an element representing the absolute style properties style:property  ** -->
  363.                 <xsl:choose>
  364.                     <xsl:when test="$defaultFamilyStyles/style[@style:family=current()/@style:family]">
  365.                         <xsl:call-template name="inherit-style-for-self-and-children">
  366.                             <xsl:with-param name="globalData" select="$globalData" />
  367.                             <xsl:with-param name="inheritedStyleProperties" select="$defaultFamilyStyles/style[@style:family=current()/@style:family]/style:properties" />
  368.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="true()" />
  369.                         </xsl:call-template>
  370.                     </xsl:when>
  371.                     <xsl:otherwise>
  372.                         <xsl:call-template name="inherit-style-for-self-and-children">
  373.                             <xsl:with-param name="globalData" select="$globalData" />
  374.                             <xsl:with-param name="inheritedStyleProperties" select="$defaultOfficeStyle/style/style:properties" />
  375.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="true()" />
  376.                         </xsl:call-template>
  377.                     </xsl:otherwise>
  378.                 </xsl:choose>
  379.  
  380.             </xsl:for-each>
  381.  
  382.         </xsl:element>
  383.        <!-- debug output in case only styles should be given out (regression test)  -->
  384.         <xsl:if test="$onlyStyleOutputEnabled">
  385.             <xsl:element name="defaultOfficeStyle" namespace="">
  386.                 <xsl:copy-of select="$defaultOfficeStyle" />
  387.             </xsl:element>
  388.             <xsl:element name="defaultFamilyStyles" namespace="">
  389.                 <xsl:copy-of select="$defaultFamilyStyles" />
  390.             </xsl:element>
  391.         </xsl:if>
  392.  
  393.     </xsl:template>
  394.  
  395.  
  396.     <xsl:template name="inherit-style-for-self-and-children">
  397.         <xsl:param name="globalData" />
  398.         <xsl:param name="inheritedStyleProperties" />
  399.         <xsl:param name="searchOnlyInAutomaticStyles" />
  400.  
  401.            <!--** create an absolute style by inherting properties from the given parent properties **-->
  402.         <xsl:variable name="newStyleProperties-RTF">
  403.             <xsl:call-template name="create-inherited-style-properties">
  404.                 <xsl:with-param name="inheritedStyleProperties" select="$inheritedStyleProperties" />
  405.             </xsl:call-template>
  406.         </xsl:variable>
  407.  
  408.            <!-- debug output in case only styles should be given out (regression test)
  409.            <xsl:if test="$onlyStyleOutputEnabled">
  410.                <xsl:element name="parent" namespace="">
  411.                    <xsl:copy-of select="$inheritedStyleProperties" />
  412.                </xsl:element>
  413.                <xsl:element name="child" namespace="">
  414.                    <xsl:copy-of select="style:properties" />
  415.                </xsl:element>
  416.                <xsl:element name="inherited" namespace="">
  417.                    <xsl:copy-of select="$newStyleProperties-RTF" />
  418.                </xsl:element>
  419.            </xsl:if>-->
  420.  
  421.         <xsl:choose>
  422.             <xsl:when test="function-available('xalan:nodeset')">
  423.                 <xsl:variable name="newStyleProperties" select="xalan:nodeset($newStyleProperties-RTF)" />
  424.  
  425.                 <xsl:element name="style" namespace="">
  426.                     <xsl:copy-of select="@style:family" />
  427.                     <xsl:copy-of select="@style:name" />
  428.                     <xsl:copy-of select="$newStyleProperties" />
  429.                 </xsl:element>
  430.  
  431.                 <xsl:choose>
  432.                     <xsl:when test="$searchOnlyInAutomaticStyles">
  433.                         <xsl:call-template name="get-children">
  434.                             <xsl:with-param name="globalData" select="$globalData" />
  435.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="true()" />
  436.                             <xsl:with-param name="inheritedStyleProperties" select="$newStyleProperties/style:properties" />
  437.                         </xsl:call-template>
  438.                     </xsl:when>
  439.                     <xsl:otherwise>
  440.                            <!--** for all automatic-children of the current office:styles  **-->
  441.                         <xsl:call-template name="get-children">
  442.                             <xsl:with-param name="globalData" select="$globalData" />
  443.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="false()" />
  444.                             <xsl:with-param name="inheritedStyleProperties" select="$newStyleProperties/style:properties" />
  445.                         </xsl:call-template>
  446.                     </xsl:otherwise>
  447.                 </xsl:choose>
  448.             </xsl:when>
  449.             <xsl:when test="function-available('xt:node-set')">
  450.                 <xsl:variable name="newStyleProperties" select="xt:node-set($newStyleProperties-RTF)" />
  451.  
  452.                 <xsl:element name="style" namespace="">
  453.                     <xsl:copy-of select="@style:family" />
  454.                     <xsl:copy-of select="@style:name" />
  455.                     <xsl:copy-of select="$newStyleProperties" />
  456.                 </xsl:element>
  457.  
  458.                 <xsl:choose>
  459.                     <xsl:when test="$searchOnlyInAutomaticStyles">
  460.                         <xsl:call-template name="get-children">
  461.                             <xsl:with-param name="globalData" select="$globalData" />
  462.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="true()" />
  463.                             <xsl:with-param name="inheritedStyleProperties" select="$newStyleProperties/style:properties" />
  464.                         </xsl:call-template>
  465.                     </xsl:when>
  466.                     <xsl:otherwise>
  467.                            <!--** for all automatic-children of the current office:styles  **-->
  468.                         <xsl:call-template name="get-children">
  469.                             <xsl:with-param name="globalData" select="$globalData" />
  470.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="false()" />
  471.                             <xsl:with-param name="inheritedStyleProperties" select="$newStyleProperties/style:properties" />
  472.                         </xsl:call-template>
  473.                     </xsl:otherwise>
  474.                 </xsl:choose>
  475.             </xsl:when>
  476.             <xsl:when test="function-available('common:node-set')">
  477.                 <xsl:variable name="newStyleProperties" select="common:node-set($newStyleProperties-RTF)" />
  478.  
  479.                 <xsl:element name="style" namespace="">
  480.                     <xsl:copy-of select="@style:family" />
  481.                     <xsl:copy-of select="@style:name" />
  482.                     <xsl:copy-of select="$newStyleProperties" />
  483.                 </xsl:element>
  484.  
  485.                 <xsl:choose>
  486.                     <xsl:when test="$searchOnlyInAutomaticStyles">
  487.                         <xsl:call-template name="get-children">
  488.                             <xsl:with-param name="globalData" select="$globalData" />
  489.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="true()" />
  490.                             <xsl:with-param name="inheritedStyleProperties" select="$newStyleProperties/style:properties" />
  491.                         </xsl:call-template>
  492.                     </xsl:when>
  493.                     <xsl:otherwise>
  494.                            <!--** for all automatic-children of the current office:styles  **-->
  495.                         <xsl:call-template name="get-children">
  496.                             <xsl:with-param name="globalData" select="$globalData" />
  497.                             <xsl:with-param name="searchOnlyInAutomaticStyles" select="false()" />
  498.                             <xsl:with-param name="inheritedStyleProperties" select="$newStyleProperties/style:properties" />
  499.                         </xsl:call-template>
  500.                     </xsl:otherwise>
  501.                 </xsl:choose>
  502.             </xsl:when>
  503.             <xsl:otherwise>
  504.                 <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  505.             </xsl:otherwise>
  506.         </xsl:choose>
  507.     </xsl:template>
  508.  
  509.  
  510.     <xsl:template name="get-children">
  511.         <xsl:param name="globalData" />
  512.         <xsl:param name="searchOnlyInAutomaticStyles" />
  513.         <xsl:param name="inheritedStyleProperties" select="@style:properties" />
  514.  
  515. <!-- QUESTION: Parent style is only unique by name and family, but what about cross family inheritance? -->
  516.        <!-- For each child style (that is every style which has the given parentStyleName as style:parent-style-name and the same style:family -->
  517.         <xsl:variable name="parentStyleFamily" select="@style:family" />
  518.         <xsl:variable name="parentStyleName" select="@style:name" />
  519.         <xsl:if test="not($searchOnlyInAutomaticStyles)">
  520.             <xsl:for-each select="$globalData/office:styles/style:style[@style:family=$parentStyleFamily and @style:parent-style-name=$parentStyleName]">
  521.                 <xsl:call-template name="inherit-style-for-self-and-children">
  522.                     <xsl:with-param name="globalData" select="$globalData" />
  523.                     <xsl:with-param name="inheritedStyleProperties" select="$inheritedStyleProperties" />
  524.                     <xsl:with-param name="searchOnlyInAutomaticStyles" select="$searchOnlyInAutomaticStyles" />
  525.                 </xsl:call-template>
  526.             </xsl:for-each>
  527.         </xsl:if>
  528.         <xsl:for-each select="$globalData/office:automatic-styles/style:style[@style:family=$parentStyleFamily and @style:parent-style-name=$parentStyleName]">
  529.             <xsl:call-template name="inherit-style-for-self-and-children">
  530.                 <xsl:with-param name="globalData" select="$globalData" />
  531.                 <xsl:with-param name="inheritedStyleProperties" select="$inheritedStyleProperties" />
  532.                 <xsl:with-param name="searchOnlyInAutomaticStyles" select="$searchOnlyInAutomaticStyles" />
  533.             </xsl:call-template>
  534.         </xsl:for-each>
  535.     </xsl:template>
  536.  
  537.  
  538.     <xsl:template name="create-inherited-style-properties">
  539.         <xsl:param name="inheritedStyleProperties" />
  540.  
  541.         <xsl:element name="style:properties">
  542.  
  543.            <!-- Writing all inherited style properties -->
  544.             <xsl:for-each select="$inheritedStyleProperties/@*">
  545.                 <xsl:sort select="name(@*)" />
  546.                 <xsl:copy-of select="." />
  547.             </xsl:for-each>
  548.  
  549.            <!--All current attributes will override already inserted attributes of the same name
  550.                XSLT Spec: "Adding an attribute to an element replaces any existing attribute of that element with the same expanded-name." -->
  551.             <xsl:for-each select="style:properties/@*[name() != 'style:font-size-rel']">
  552.                 <xsl:copy-of select="." />
  553.             </xsl:for-each>
  554.  
  555.             <xsl:if test="style:properties/@style:font-size-rel">
  556.                 <xsl:variable name="fontSizeAbsolute">
  557.                     <xsl:call-template name="convert2pt">
  558.                         <xsl:with-param name="value" select="$inheritedStyleProperties/@fo:font-size" />
  559.                     </xsl:call-template>
  560.                 </xsl:variable>
  561.                 <xsl:variable name="fontSizeRelative">
  562.                     <xsl:call-template name="convert2pt">
  563.                         <xsl:with-param name="value" select="style:properties/@style:font-size-rel" />
  564.                     </xsl:call-template>
  565.                 </xsl:variable>
  566.  
  567.                 <xsl:attribute name="fo:font-size">
  568.                     <xsl:value-of select="$fontSizeAbsolute + $fontSizeRelative"/><xsl:text>pt</xsl:text>
  569.                 </xsl:attribute>
  570.             </xsl:if>
  571.  
  572.            <!-- inner elements are not copied (e.g. 'style:tab-stops' from the style -->
  573.         </xsl:element>
  574.     </xsl:template>
  575.  
  576.    <!-- debugging & testing purpose -->
  577.     <xsl:template name="write-collected-styles">
  578.         <xsl:param name="globalData" />
  579.  
  580.         <xsl:message><all-ooo-styles></xsl:message>
  581.         <xsl:for-each select="$globalData/all-ooo-styles/style">
  582.             <xsl:message><style</xsl:message>
  583.             <xsl:message>style:family="<xsl:value-of select="current()/@style:family" />"></xsl:message>
  584.             <xsl:message>style:name="<xsl:value-of select="current()/@style:name" />" </xsl:message>
  585.             <xsl:message>   <style:properties</xsl:message>
  586.             <xsl:for-each select="style:properties/@*">
  587.                 <xsl:message>
  588.                     <xsl:text>       </xsl:text>
  589.                     <xsl:value-of select="name()" />="<xsl:value-of select="." />"</xsl:message>
  590.             </xsl:for-each>
  591.             <xsl:message>/></xsl:message>
  592.             <xsl:message></style></xsl:message>
  593.         </xsl:for-each>
  594.         <xsl:message></all-ooo-styles></xsl:message>
  595.     </xsl:template>
  596.  
  597.  
  598.  
  599.     <xsl:template name="map-ooo-style-properties">
  600.         <xsl:param name="globalData" />
  601.  
  602.         <xsl:choose>
  603.            <!--+++++ DEBUG STYLE OUTPUT FOR REGRESSION TEST +++++-->
  604.            <!-- create styles file from the style variable (testing switch) -->
  605.             <xsl:when test="$onlyStyleOutputEnabled">
  606.  
  607.                 <xsl:element name="debug-output" namespace="">
  608.                     <xsl:copy-of select="$globalData" />
  609.                     <xsl:call-template name="map-ooo-properties">
  610.                         <xsl:with-param name="globalData" select="$globalData" />
  611.                     </xsl:call-template>
  612.                 </xsl:element>
  613.             </xsl:when>
  614.  
  615.            <!-- create XHTML file -->
  616.             <xsl:otherwise>
  617.                <!-- to access the variable like a node-set it is necessary to convert it
  618.                     from a result-tree-fragment (RTF) to a node set using the James Clark extension -->
  619.                 <xsl:variable name="globalDataRTF">
  620.                    <!-- raw properties still needed for table width attribute creation -->
  621.                     <xsl:copy-of select="$globalData" />
  622.                     <xsl:call-template name="map-ooo-properties">
  623.                         <xsl:with-param name="globalData" select="$globalData" />
  624.                     </xsl:call-template>
  625.                 </xsl:variable>
  626.  
  627.                 <xsl:choose>
  628.                     <xsl:when test="function-available('xalan:nodeset')">
  629.                         <xsl:call-template name="start-main">
  630.                             <xsl:with-param name="globalData" select="xalan:nodeset($globalDataRTF)" />
  631.                         </xsl:call-template>
  632.                     </xsl:when>
  633.                     <xsl:when test="function-available('xt:node-set')">
  634.                         <xsl:call-template name="start-main">
  635.                             <xsl:with-param name="globalData" select="xt:node-set($globalDataRTF)" />
  636.                         </xsl:call-template>
  637.                     </xsl:when>
  638.                     <xsl:when test="function-available('common:node-set')">
  639.                         <xsl:call-template name="start-main">
  640.                             <xsl:with-param name="globalData" select="common:node-set($globalDataRTF)" />
  641.                         </xsl:call-template>
  642.                     </xsl:when>
  643.                     <xsl:otherwise>
  644.                         <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  645.                     </xsl:otherwise>
  646.                 </xsl:choose>
  647.             </xsl:otherwise>
  648.         </xsl:choose>
  649.     </xsl:template>
  650.  
  651.     <!-- REASON FOR TEMPLATE:
  652.        The OpenOffice style properities gathered in the variable 'globalData' have to be mapped to the CSS style format
  653.     -->
  654.     <xsl:template name="map-ooo-properties">
  655.         <xsl:param name="globalData" />
  656.  
  657.         <xsl:element name="all-styles" namespace="">
  658.             <xsl:for-each select="$globalData/all-ooo-styles/style">
  659.                 <xsl:sort select="@style:family" />
  660.                 <xsl:sort select="@style:name" />
  661.                 <xsl:element name="style" namespace="">
  662.                     <xsl:copy-of select="@style:family" />
  663.                     <xsl:copy-of select="@style:name" />
  664.                     <xsl:element name="final-properties" namespace="">
  665.                         <xsl:call-template name="write-style-properties">
  666.                             <xsl:with-param name="globalData" select="$globalData" />
  667.                             <xsl:with-param name="style:properties" select="style:properties" />
  668.                         </xsl:call-template>
  669.                     </xsl:element>
  670.                 </xsl:element>
  671.             </xsl:for-each>
  672.         </xsl:element>
  673.     </xsl:template>
  674.  
  675. </xsl:stylesheet>
  676.